package com.aaa.javaweb.dao.impl;

import com.aaa.javaweb.dao.YdclDao;
import com.aaa.javaweb.entity.RuzhuDetail;
import com.aaa.javaweb.until.JDBCUntil;
import jdk.nashorn.internal.scripts.JD;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class YdclDaoImpl implements YdclDao {
    @Override
    public List<Map> selkongxian(String name) {
        String sql ="select t_room.id,t_room.roomcode,t_room.status,t_type.tname,t_type.yj,t_type.money from t_room join t_type on t_room.typeid=t_type.id where t_room.status=2 and t_type.tname=?";
        return JDBCUntil.selectMap(sql,name);
    }

    @Override
    public int addruzhu(RuzhuDetail ruzhuDetail) {
        String sql="insert into t_ruzhudetail(name,tel,idcard,orderid,roomid,rzyj) values(?,?,?,?,?,?)";
        return JDBCUntil.Updateout(sql,ruzhuDetail.getName(),ruzhuDetail.getTel(),ruzhuDetail.getIdcard(),ruzhuDetail.getId(),ruzhuDetail.getRoomcode(),ruzhuDetail.getYj());
    }

    @Override
    public int updroomstatus(Integer roomcode) {
        String sql="update t_room set status=0 where roomcode=?";

        return JDBCUntil.Updateout(sql,roomcode);
    }

    @Override
    public int updroomorde(Integer id) {
        String sql="update t_order set status=1 where id=?";

        return JDBCUntil.Updateout(sql,id);
    }

    @Override
    public Map selcon(RuzhuDetail ruzhuDetail) {
        String sql="select tr.count as a,count(tu.orderid) as b from t_order tr left join t_ruzhudetail tu on tr.id=tu.orderid where tu.orderid=?";
        List<Map> maps = JDBCUntil.selectMap(sql,ruzhuDetail.getId());
        System.out.println("========="+maps);
        int count = Integer.parseInt(maps.get(0).get("count") + "");
        int b = Integer.parseInt(maps.get(0).get("b") + "");
        System.out.println("========="+count+"++++++"+b);
        Map m = new HashMap();
        m.put("count",count);
        m.put("b",b);

        return m;
    }

    @Override
    public List<Map> updruzhustatus(Integer roomcode) {
        String sql ="SELECT t_ruzhudetail.id,t_tuifang.outdate from t_ruzhudetail JOIN t_tuifang ON t_tuifang.ruzhuid=t_ruzhudetail.id where t_tuifang.outdate =(SELECT MAX(outdate) FROM t_tuifang) and t_ruzhudetail.roomid=?";
        return JDBCUntil.selectMap(sql,roomcode);

    }

    @Override
    public int updatesta(int i1) {
        String sql ="update t_ruzhudetail set status=0 where id=?";
        return JDBCUntil.Updateout(sql,i1);

    }



    /*@Override
    public Map selectcount(Integer id) {
        String sql="select tr.count as a,count(tu.orderid) as b from t_order tr left join t_ruzhudetail tu on tr.id=tu.orderid where tu.orderid=?";
        List<Map> maps = JDBCUntil.selectMap(sql, id);
        int a = Integer.parseInt(maps.get(0).get("a") + "");
        int b = Integer.parseInt(maps.get(0).get("b") + "");
        Map m = new HashMap();
        m.put("a",a);
        m.put("b",b);
        return m;
    }*/
}
